package com.demo2do.fms.entity.business.balance;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.demo2do.core.utils.DateFormatUtils;
import com.demo2do.fms.entity.business.Finance;
import com.demo2do.fms.entity.data.business.City;
import com.demo2do.fms.entity.data.business.Province;
import com.demo2do.fms.entity.data.business.Warehouse;

/**
 * SAP收入
 * 
 * @author Ysy
 *
 */
@Entity
@Table(name = "TBL_SAP_REVENUE_DETAIL")
public class SapRevenueDetail {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** financeId */
    private Long financeId;
    
    /** 状态 */
    private String states;
    
    /** 原始收入订单号 */
    private String aysrdh;
    
    /** 调度单号 */
    private String ayhddd;
    
    /** 合并目标的调度单号 */
    private String ayhdddd;
    
    /** 商品车vin码 */
    private String ayvin;
    
    /** 公司代码 */
    private String bukrs;
    
    /** 客户代码 */
    private String aykhdm;
    
    /** 
     * 业内或业外标志
     *      
     *      - X     业内
     *      - 空字符      业外
     */
    private String aynwbz;
    
    /** 制造商 */
    private String ayzzdm;
    
    /** 出发城市 */
    private String ayqsdd;

    /** 出发城市名称 */
    private String ayqsddmc;

    /** 出发省份 */
    private String ayqsddsf;

    /** 目的城市 */
    private String aydddd;

    /** 目的城市名称 */
    private String ayddddmc;

    /** 目的省份 */
    private String ayddddsf;
    
    /** 结算公里数 */
    private String ayjsgl;
    
    /** 运输收入 */
    private String ayyysr;
    
    /** 运输单价 */
    private String ayydj;
    
    /** 订单建立日期 */
    private String ayddrq;
    
    /** 传入SAP系统的日期 */
    private String aydrrq;
    
    /** 暂估标志  */
    private String zmzgbz;
    
    /** 
     * 批量更改更新标识
     *      
     *      -  I  插入
     *      -  U  更新
     *      -  X  删除
     */
    private String ayggbz;
    
    /** 最后更改日期 */
    private String ayggrq;
    
    private String ayhdbs;
    
    /** 回单日期 */
    private String ayhdrq;
    
    /** 起始地 片区 */
    private String aypqdm1;

    /** 起始地 片区名称 */
    private String aypodmc1;

    /** 目的地 片区 */
    private String aypqdm2;

    /** 目的地 片区名称 */
    private String aypodmc2;
    
    private String ayclsl;
    
    private String ayjscl;
    
    /**
     * 收入是否可结算
     * 
     * 		- N 不可结算
     * 		- Y 可结算
     */
    private String aykjs;
    
    private String aydydd;
    
    /** 运输方式 */
    private String ayysfs;
    
    /** 运输方式名称  */
    private String ayysfsmc;
    
    private String zydttq;
    
    private String aysvin;
    
    private String sessionId;
    
    @Column(name = "is_disabled")
    private Boolean disabled;
    
    /**
     * 
     */
    public SapRevenueDetail() {
        
    }
    
    /**
     * init by revenue_little & order
     * 
     * @param revenueLittle
     * @param order
     * @return
     */
    public SapRevenueDetail init(RevenueLittle revenueLittle, Order order) {
        
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
        
        this.aysrdh = revenueLittle.getSmOid().toString();
        
        if(order != null) {
            this.aydydd = order.getCode();
        }
        
        this.ayvin = "";
        this.ayhddd = revenueLittle.getFnLn();
        this.ayhdddd = "";
        this.aysvin = revenueLittle.getSysVinCode();
        this.bukrs = revenueLittle.getVtcCode();
        
        this.ayysfs = revenueLittle.getSmTt();
        this.ayysfsmc = revenueLittle.getSmTtname();
        this.ayzzdm = revenueLittle.getVmCode();
        
        this.ayqsdd = revenueLittle.getVc1Code();
        this.ayqsddmc = revenueLittle.getVc1Name();
        this.ayqsddsf = revenueLittle.getVc1Pname();
        
        this.aydddd = revenueLittle.getVc2Code();
        this.ayddddmc = revenueLittle.getVc2Name();
        this.ayddddsf = revenueLittle.getVc2Pname();
        
        this.ayjsgl = decimalFormat.format(revenueLittle.getKilo());
        this.ayyysr = decimalFormat.format(revenueLittle.getFee());
        this.ayydj = decimalFormat.format(revenueLittle.getFeeRate());
        this.ayclsl = revenueLittle.getQuantity().toString();
        
        this.aypqdm1 = revenueLittle.getVp1Code();
        this.aypodmc1 = revenueLittle.getVp1Name();
        this.aypqdm2 = revenueLittle.getVp2Code();
        this.aypodmc2 = revenueLittle.getVp2Name();
        
        this.ayjscl = this.ayjsgl;
        this.zmzgbz = "";
        this.ayggbz = "I";
        this.ayhdbs = "";
        this.ayggrq = null;
        this.ayhdrq = null;
        this.ayddrq = null;
        this.aykjs = "N";
        
        this.aydrrq = DateFormatUtils.format(new Date(), "yyyyMMdd");
        this.zydttq = DateFormatUtils.format(new Date(), "HH:mm:ss");
        this.disabled = false;
        
        return this;
    }
    
    /**
     * edit session id
     * 
     * @param sessionId
     * @return
     */
    public SapRevenueDetail editSessionId(String sessionId) {
        this.sessionId = sessionId;
        return this;
    }
    
    /**
     * edit some basic info
     * 
     * @param states
     * @param financeId
     * @return
     */
    public SapRevenueDetail editBasic(String states, Long financeId){
        this.states = states;
        this.financeId = financeId;
        return this;
    }
    
    /**
     * edit about organization
     * 
     * @param bukrs
     * @return
     */
    public SapRevenueDetail editOrganization(String bukrs){
        this.bukrs = bukrs;
        return this;
    }
    
    /**
     * edit about manufactor
     * 
     * @param ayzzdm
     * @return
     */
    public SapRevenueDetail editManufactor(String ayzzdm){
        this.ayzzdm = ayzzdm;
        return this;
    }
    
    /**
     * edit about client
     * 
     * @param aykhdm
     * @return
     */
    public SapRevenueDetail editClient(String aykhdm){
        this.aykhdm = aykhdm;
        return this;
    }
    
    /**
     * edit about temporary
     * 
     * @param zmzgbz
     * @return
     */
    public SapRevenueDetail editTemporary(String zmzgbz){
        this.zmzgbz = zmzgbz;
        return this;
    }
    
    /**
     * edit about trans_type
     * 
     * @param ayysfs
     * @param ayysfsmc
     * @return
     */
    public SapRevenueDetail editTransType(String ayysfs, String ayysfsmc){
        this.ayysfs = ayysfs;
        this.ayysfsmc = ayysfsmc;
        return this;
    }
    
    /**
     * edit accomplish confirm
     * 
     * @param ayhdbs
     * @return
     */
    public SapRevenueDetail editAccomplishConfirm(String ayhdbs){
        this.ayhdbs = ayhdbs;
        this.ayhdrq = DateFormatUtils.format(new Date(), "yyyyMMdd");
        return this;
    }
    
    /**
     * edit accomplish confirm
     * 
     * @param ayhdbs
     * @param ayhdrq
     * @return
     */
    public SapRevenueDetail editAccomplishConfirm(String ayhdbs, String ayhdrq){
        this.ayhdbs = ayhdbs;
        this.ayhdrq = ayhdrq;
        return this;
    }
    
    /**
     * edit about location
     * 
     * @param srcWh
     * @param destWh
     * @return
     */
    public SapRevenueDetail editLocation(Warehouse srcWh, Warehouse destWh){
        
        City srcCity = srcWh.getCity();
        Province srcProvince = srcCity.getProvince();
        
        City destCity = destWh.getCity();
        Province destProvince = destCity.getProvince();
        
        this.ayqsdd = srcCity.getCode();
        this.ayqsddmc = srcCity.getName();
        this.ayqsddsf = srcProvince.getName();
        this.aypqdm1 = srcProvince.getAreaCode();
        this.aypodmc1 = srcProvince.getAreaName();
        
        this.aydddd = destCity.getCode();
        this.ayddddmc = destCity.getName();
        this.ayddddsf = destProvince.getName();
        this.aypqdm2 = destProvince.getAreaCode();
        this.aypodmc2 = destProvince.getAreaName();
        
        return this;
    }
    
    /**
     * edit about finance
     * 
     * @param finance
     * @return
     */
    public SapRevenueDetail editFinance(Finance finance){
        
        this.ayclsl = "1";
        this.ayjsgl = finance.getKilometer().toString();
        this.ayjscl = this.ayjsgl;
        this.ayyysr = finance.getFee().setScale(2, RoundingMode.HALF_UP).toString();
        this.ayydj = finance.getFeeRate().setScale(2, RoundingMode.HALF_UP).toString();
        
        return this;
    }
    
    /**
     * edit financeId
     * 
     * @param financeId
     * @return
     */
    public SapRevenueDetail editFinanceId(Long financeId) {
        this.financeId = financeId;
        return this;
    }
    
    /**
     * edit ayvin
     * 
     * @param ayvin
     * @return
     */
    public SapRevenueDetail editVinCode(String ayvin){
        this.ayvin = ayvin;
        return this;
    }
    
    /**
     * edit about vin_code
     * 
     * @param ayvin
     * @param aysvin
     * @return
     */
    public SapRevenueDetail editVinCode(String ayvin, String aysvin){
        this.ayvin = ayvin;
        this.aysvin = aysvin;
        return this;
    }
    
    /**
     * 调度单号
     * 
     * @param ayhddd
     * @return
     */
    public SapRevenueDetail editShipmentOrder(String ayhddd){
        this.ayhddd = ayhddd;
        return this;
    }
    
    /**
     * 合并后调度指令号
     * 
     * @param ayhdddd
     * @return
     */
    public SapRevenueDetail editMergeLoadnumber(String ayhdddd) {
        this.ayhdddd = ayhdddd;
        return this;
    }
    
    /**
     * 订单创建日期
     * 
     * @param ayddrq
     * @return
     */
    public SapRevenueDetail editOrderCreateDate(String ayddrq){
        this.ayddrq = ayddrq;
        return this;
    }
    
    /**
     * edit 业内、业外标识
     * 
     * @param aynwbz
     * @return
     */
    public SapRevenueDetail editBusinessIndentify(String aynwbz){
        this.aynwbz = aynwbz;
        return this;
    }
    
    /**
     * @param aydydd
     * @return
     */
    public SapRevenueDetail editOrderCode(String aydydd) {
        this.aydydd = aydydd;
        return this;
    }
    
    /**
     * edit
     * 
     * @param aysrdh
     * @param ayggbz
     * @param aykjs
     * @param aydydd
     * @param ayhdddd
     * @param ayggrq
     * @return
     */
    public SapRevenueDetail editSapField(String aysrdh, String ayggbz, String aykjs, String aydydd, String ayhdddd, String ayggrq){
        this.aysrdh = aysrdh;
        this.ayggbz = ayggbz;
        this.aykjs = aykjs;
        this.aydrrq = DateFormatUtils.format(new Date(), "yyyyMMdd");
        this.aydydd = aydydd;
        this.ayhdddd = ayhdddd;
        this.ayggrq = ayggrq;
        return this;
    }
    
    /**
     * @param aykjs
     * @return
     */
    public SapRevenueDetail editAykjs(String aykjs) {
        this.aykjs = aykjs;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the financeId
     */
    public Long getFinanceId() {
        return financeId;
    }

    /**
     * @return the states
     */
    public String getStates() {
        return states;
    }

    /**
     * @return the aysrdh
     */
    public String getAysrdh() {
        return aysrdh;
    }

    /**
     * @return the ayhddd
     */
    public String getAyhddd() {
        return ayhddd;
    }

    /**
     * @return the ayhdddd
     */
    public String getAyhdddd() {
        return ayhdddd;
    }

    /**
     * @return the ayvin
     */
    public String getAyvin() {
        return ayvin;
    }

    /**
     * @return the bukrs
     */
    public String getBukrs() {
        return bukrs;
    }

    /**
     * @return the aykhdm
     */
    public String getAykhdm() {
        return aykhdm;
    }

    /**
     * @return the aynwbz
     */
    public String getAynwbz() {
        return aynwbz;
    }

    /**
     * @return the ayzzdm
     */
    public String getAyzzdm() {
        return ayzzdm;
    }

    /**
     * @return the ayqsdd
     */
    public String getAyqsdd() {
        return ayqsdd;
    }

    /**
     * @return the ayqsddmc
     */
    public String getAyqsddmc() {
        return ayqsddmc;
    }

    /**
     * @return the ayqsddsf
     */
    public String getAyqsddsf() {
        return ayqsddsf;
    }

    /**
     * @return the aydddd
     */
    public String getAydddd() {
        return aydddd;
    }

    /**
     * @return the ayddddmc
     */
    public String getAyddddmc() {
        return ayddddmc;
    }

    /**
     * @return the ayddddsf
     */
    public String getAyddddsf() {
        return ayddddsf;
    }

    /**
     * @return the ayjsgl
     */
    public String getAyjsgl() {
        return ayjsgl;
    }

    /**
     * @return the ayyysr
     */
    public String getAyyysr() {
        return ayyysr;
    }

    /**
     * @return the ayydj
     */
    public String getAyydj() {
        return ayydj;
    }

    /**
     * @return the ayddrq
     */
    public String getAyddrq() {
        return ayddrq;
    }

    /**
     * @return the aydrrq
     */
    public String getAydrrq() {
        return aydrrq;
    }

    /**
     * @return the zmzgbz
     */
    public String getZmzgbz() {
        return zmzgbz;
    }

    /**
     * @return the ayggbz
     */
    public String getAyggbz() {
        return ayggbz;
    }

    /**
     * @return the ayggrq
     */
    public String getAyggrq() {
        return ayggrq;
    }

    /**
     * @return the ayhdbs
     */
    public String getAyhdbs() {
        return ayhdbs;
    }

    /**
     * @return the ayhdrq
     */
    public String getAyhdrq() {
        return ayhdrq;
    }

    /**
     * @return the aypqdm1
     */
    public String getAypqdm1() {
        return aypqdm1;
    }

    /**
     * @return the aypodmc1
     */
    public String getAypodmc1() {
        return aypodmc1;
    }

    /**
     * @return the aypqdm2
     */
    public String getAypqdm2() {
        return aypqdm2;
    }

    /**
     * @return the aypodmc2
     */
    public String getAypodmc2() {
        return aypodmc2;
    }

    /**
     * @return the ayclsl
     */
    public String getAyclsl() {
        return ayclsl;
    }

    /**
     * @return the ayjscl
     */
    public String getAyjscl() {
        return ayjscl;
    }

    /**
     * @return the aykjs
     */
    public String getAykjs() {
        return aykjs;
    }

    /**
     * @return the aydydd
     */
    public String getAydydd() {
        return aydydd;
    }

    /**
     * @return the ayysfs
     */
    public String getAyysfs() {
        return ayysfs;
    }

    /**
     * @return the ayysfsmc
     */
    public String getAyysfsmc() {
        return ayysfsmc;
    }

    /**
     * @return the zydttq
     */
    public String getZydttq() {
        return zydttq;
    }

    /**
     * @return the aysvin
     */
    public String getAysvin() {
        return aysvin;
    }
    
    /**
     * @return
     */
    public String getSessionId() {
        return sessionId;
    }

    /**
     * @return the disabled
     */
    public Boolean getDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param financeId the financeId to set
     */
    public void setFinanceId(Long financeId) {
        this.financeId = financeId;
    }

    /**
     * @param states the states to set
     */
    public void setStates(String states) {
        this.states = states;
    }

    /**
     * @param aysrdh the aysrdh to set
     */
    public void setAysrdh(String aysrdh) {
        this.aysrdh = aysrdh;
    }

    /**
     * @param ayhddd the ayhddd to set
     */
    public void setAyhddd(String ayhddd) {
        this.ayhddd = ayhddd;
    }

    /**
     * @param ayhdddd the ayhdddd to set
     */
    public void setAyhdddd(String ayhdddd) {
        this.ayhdddd = ayhdddd;
    }

    /**
     * @param ayvin the ayvin to set
     */
    public void setAyvin(String ayvin) {
        this.ayvin = ayvin;
    }

    /**
     * @param bukrs the bukrs to set
     */
    public void setBukrs(String bukrs) {
        this.bukrs = bukrs;
    }

    /**
     * @param aykhdm the aykhdm to set
     */
    public void setAykhdm(String aykhdm) {
        this.aykhdm = aykhdm;
    }

    /**
     * @param aynwbz the aynwbz to set
     */
    public void editedit(String aynwbz) {
        this.aynwbz = aynwbz;
    }

    /**
     * @param ayzzdm the ayzzdm to set
     */
    public void setAyzzdm(String ayzzdm) {
        this.ayzzdm = ayzzdm;
    }

    /**
     * @param ayqsdd the ayqsdd to set
     */
    public void setAyqsdd(String ayqsdd) {
        this.ayqsdd = ayqsdd;
    }

    /**
     * @param ayqsddmc the ayqsddmc to set
     */
    public void setAyqsddmc(String ayqsddmc) {
        this.ayqsddmc = ayqsddmc;
    }

    /**
     * @param ayqsddsf the ayqsddsf to set
     */
    public void setAyqsddsf(String ayqsddsf) {
        this.ayqsddsf = ayqsddsf;
    }

    /**
     * @param aydddd the aydddd to set
     */
    public void setAydddd(String aydddd) {
        this.aydddd = aydddd;
    }

    /**
     * @param ayddddmc the ayddddmc to set
     */
    public void setAyddddmc(String ayddddmc) {
        this.ayddddmc = ayddddmc;
    }

    /**
     * @param ayddddsf the ayddddsf to set
     */
    public void setAyddddsf(String ayddddsf) {
        this.ayddddsf = ayddddsf;
    }

    /**
     * @param ayjsgl the ayjsgl to set
     */
    public void setAyjsgl(String ayjsgl) {
        this.ayjsgl = ayjsgl;
    }

    /**
     * @param ayyysr the ayyysr to set
     */
    public void setAyyysr(String ayyysr) {
        this.ayyysr = ayyysr;
    }

    /**
     * @param ayydj the ayydj to set
     */
    public void setAyydj(String ayydj) {
        this.ayydj = ayydj;
    }

    /**
     * @param ayddrq the ayddrq to set
     */
    public void setAyddrq(String ayddrq) {
        this.ayddrq = ayddrq;
    }

    /**
     * @param aydrrq the aydrrq to set
     */
    public void setAydrrq(String aydrrq) {
        this.aydrrq = aydrrq;
    }

    /**
     * @param zmzgbz the zmzgbz to set
     */
    public void setZmzgbz(String zmzgbz) {
        this.zmzgbz = zmzgbz;
    }

    /**
     * @param ayggbz the ayggbz to set
     */
    public void setAyggbz(String ayggbz) {
        this.ayggbz = ayggbz;
    }

    /**
     * @param ayggrq the ayggrq to set
     */
    public void setAyggrq(String ayggrq) {
        this.ayggrq = ayggrq;
    }

    /**
     * @param ayhdbs the ayhdbs to set
     */
    public void setAyhdbs(String ayhdbs) {
        this.ayhdbs = ayhdbs;
    }

    /**
     * @param ayhdrq the ayhdrq to set
     */
    public void setAyhdrq(String ayhdrq) {
        this.ayhdrq = ayhdrq;
    }

    /**
     * @param aypqdm1 the aypqdm1 to set
     */
    public void setAypqdm1(String aypqdm1) {
        this.aypqdm1 = aypqdm1;
    }

    /**
     * @param aypodmc1 the aypodmc1 to set
     */
    public void setAypodmc1(String aypodmc1) {
        this.aypodmc1 = aypodmc1;
    }

    /**
     * @param aypqdm2 the aypqdm2 to set
     */
    public void setAypqdm2(String aypqdm2) {
        this.aypqdm2 = aypqdm2;
    }

    /**
     * @param aypodmc2 the aypodmc2 to set
     */
    public void setAypodmc2(String aypodmc2) {
        this.aypodmc2 = aypodmc2;
    }

    /**
     * @param ayclsl the ayclsl to set
     */
    public void setAyclsl(String ayclsl) {
        this.ayclsl = ayclsl;
    }

    /**
     * @param ayjscl the ayjscl to set
     */
    public void setAyjscl(String ayjscl) {
        this.ayjscl = ayjscl;
    }

    /**
     * @param aykjs the aykjs to set
     */
    public void setAykjs(String aykjs) {
        this.aykjs = aykjs;
    }

    /**
     * @param aydydd the aydydd to set
     */
    public void setAydydd(String aydydd) {
        this.aydydd = aydydd;
    }

    /**
     * @param ayysfs the ayysfs to set
     */
    public void setAyysfs(String ayysfs) {
        this.ayysfs = ayysfs;
    }

    /**
     * @param ayysfsmc the ayysfsmc to set
     */
    public void setAyysfsmc(String ayysfsmc) {
        this.ayysfsmc = ayysfsmc;
    }

    /**
     * @param zydttq the zydttq to set
     */
    public void setZydttq(String zydttq) {
        this.zydttq = zydttq;
    }

    /**
     * @param aysvin the aysvin to set
     */
    public void setAysvin(String aysvin) {
        this.aysvin = aysvin;
    }
    
    /**
     * @param sessionId
     */
    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }
}
